import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/viewmodel/hand_over/hand_over_area_view_model.dart';
import 'package:ls_work/widgets/customer_under_line_tab_indicator.dart';

import '../../a_yyt/models/handover_new_entity.dart';
import 'hand_over_detail_fragment.dart';

class HandOverAreaPage extends BaseStatefulMvvmWidget {
  HandoverNewInfo info;

  HandOverAreaPage({required this.info});

  @override
  State<StatefulWidget> createState() => _HandOverAreaState();
}

class _HandOverAreaState
    extends BaseMvvmState<HandOverAreaViewModel, HandOverAreaPage> {
  @override
  Widget? buildLoadingContentView() {
    return DefaultTabController(
        length: viewModel.areaList.length,
        child: Column(
          children: [
            TabBar(
              isScrollable: true,
              labelStyle: TextStyle(fontSize: 17,fontWeight: FontWeight.bold),
                unselectedLabelStyle: TextStyle(fontSize: 15,fontWeight: FontWeight.normal),
                indicator: CustomUnderlineTabIndicator(
                  borderSide: BorderSide(color: Colours.app_main,width: 4),
                ),
                indicatorPadding: EdgeInsets.only(bottom: 8),
                unselectedLabelColor: Colors.black,
                labelColor: Colours.app_main,
                indicatorColor: Colours.app_main,
                tabs: viewModel.areaList
                    .map((e) => Tab(
                          text: e.name,
                        ))
                    .toList()),
            TabBarView(children: viewModel.areaList.map((e) => HandOverDetailFragment(
              info: widget.info,areaId: e.id,
            )).toList()).setWeight(1)
          ],
        ));
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text("交班信息"),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  HandOverAreaViewModel createViewModel() {
    return HandOverAreaViewModel(context, info: widget.info);
  }

  @override
  void onRetryClick() {
    viewModel.requestAreaData();
  }
}
